var app=getApp()
Page({
  data: {
    boo: !1,
    currentTab: "0",
    sizeTab: "0",
    proList: "",
    itemId: "",
    proList: {
      item: {
        images: ["/assets/images/796.png", "/assets/images/796.png", "/assets/images/796.png", "/assets/images/796.png", "/assets/images/796.png", ],
        title: '感冒药',
        sellPoint: '北京产的',
        price: 10000,
        num: 30
      },
      estimateCount: 10,
      goodDegree: 20,
      itemDesc: {
        descImages: ["/assets/images/796.png", "/assets/images/796.png", "/assets/images/796.png", "/assets/images/796.png", "/assets/images/796.png", ]
      }
    },
    promotionList: [{
        nmPromTime: '满100减30',
      },
      {
        nmPromTime: '满200减30',
      },
      {
        nmPromTime: '满300减30',
      },
      {
        nmPromTime: '满1100减30',
      },
      {
        nmPromTime: '满100减30',
      }
    ],
    promotionBoo: '',
    estimates: [{
        phoneMask: '小强',
        star: 1,
        createTime: '2018-10-26',
        estimate: '用了都说好',
        itemParam: 20
      },
      {
        phoneMask: '小强',
        star: 5,
        createTime: '2018-10-26',
        estimate: '用了都说好',
        itemParam: 20
      },
      {
        phoneMask: '小强',
        star: 3,
        createTime: '2018-10-26',
        estimate: '用了都说好',
        itemParam: 20
      },
      {
        phoneMask: '小强',
        star: 1,
        createTime: '2018-10-26',
        estimate: '用了都说好',
        itemParam: 20
      },
      {
        phoneMask: '小强',
        star: 5,
        createTime: '2018-10-26',
        estimate: '用了都说好',
        itemParam: 20
      }
    ],
    parameterList: [{
        group: '感冒药',
        params: [{
            k: '几天见效',
            v: '两天'
          },
          {
            k: '那产的',
            v: '天津'
          },
          {
            k: '还治啥',
            v: '没了'
          }
        ]
      },
      {
        group: '感冒药',
        params: [{
            k: '几天见效',
            v: '两天'
          },
          {
            k: '那产的',
            v: '天津'
          },
          {
            k: '还治啥',
            v: '没了'
          }
        ]
      }
    ]
  },
  onLoad: function(options) {
    var that = this;
    var sid = options.sid
    that.getGoodshoping(sid)
  },
  onReady: function() {
    
  },
  onShow: function() {
  },
  onHide: function() {},
  onUnload: function() {
    try {
      wx.removeStorageSync("addrList");
    } catch (t) {}
  },
  onPullDownRefresh: function() {
    var t = this;
    wx.hideToast(), wx.showNavigationBarLoading(), wx.request({
      url: e.globalData.httpOne + "mall/item/detail/" + t.data.itemId + "/" + t.data.token,
      success: function(a) {
        if (200 == a.data.code && null != a.data.data) {
          wx.hideNavigationBarLoading(), wx.stopPullDownRefresh();
          a.data.data.estimates;
          t.setData({
            proList: a.data.data
          });
        }
      },
      complete: function() {}
    });
  },
  onShareAppMessage: function(t) {
    return {
      title: this.data.proList.item.title,
      path: "/pages/index/index?flag=2&id=" + this.data.itemId
    };
  },
  swichNav: function(t) {
    var a = this;
    if (this.data.currentTab === t.target.dataset.current) return !1;
    0 != t.target.id && "" == a.data.parameterList && (wx.showLoading({
      title: "加载中",
      mask: !0
    }), wx.request({
      url: e.globalData.httpOne + "mall/item/param/" + t.target.id,
      success: function(t) {
        200 == t.data.code && (wx.hideLoading(), a.setData({
          parameterList: t.data.data
        }));
      },
      fail: function(t) {}
    })), a.setData({
      currentTab: t.target.dataset.current
    });
  },
  swichNav1: function(t) {
    var a = this;
    if (this.data.sizeTab === t.target.dataset.size) return !1;
    a.setData({
      sizeTab: t.target.dataset.size
    });
  },
  bindMinus: function() {
    var t = this.data.num;
    t <= 1 ? wx.showToast({
      title: "至少一件商品",
      icon: "none",
      duration: 1e3
    }) : (t--, this.setData({
      num: t
    }));
  },
  bindPlus: function() {
    var t = this.data.num;
    t++, this.setData({
      num: t
    });
  },
  bindManual: function(t) {
    var a = t.detail.value;
    this.setData({
      num: a
    });
  },
  addcar: function() {
    wx.request({
      url: e.globalData.httpOne + "mall/cart/add",
      data: {
        itemId: this.data.itemId,
        itemCount: this.data.num,
        cartSessionId: this.data.cartSessionId
      },
      success: function(t) {
        if (200 == t.data.code) {
          wx.showToast({
            title: "添加成功",
            icon: "success",
            duration: 1e3
          });
          try {
            wx.setStorageSync("cartSessionId", t.data.data.cartSession);
          } catch (t) {}
        }
      }
    });
  },
  getPhoneNumber: function(t) {
    var a = this;
    "getPhoneNumber:ok" == t.detail.errMsg && (a.setData({
      boo: !0
    }), wx.showModal({
      title: "温馨提示",
      showCancel: !1,
      content: "您已成功授权~",
      success: function(o) {
        wx.request({
          url: e.globalData.httpLogin + "user/phone/",
          data: {
            iv: t.detail.iv,
            encryptedData: t.detail.encryptedData,
            token: a.data.token
          },
          success: function(t) {
            if (200 == t.data.code) {
              t.data.data.token;
              var e = t.data.data.bindPhone;
              a.setData({
                boo: e
              });
              try {
                wx.setStorageSync("bindPhone", e);
              } catch (t) {}
            }
          },
          fail: function(t) {}
        });
      }
    }));
  },
  shopNow: function() {
    var t = this;
    this.data.shopBoo || wx.request({
      url: e.globalData.httpOne + "mall/order/quickBuy/orderInfo",
      data: {
        token: t.data.token,
        itemId: t.data.itemId,
        itemCount: t.data.num
      },
      success: function(t) {
        if (200 == t.data.code && t.data.data) {
          try {
            wx.setStorageSync("carData", t.data.data);
          } catch (t) {}
          wx.navigateTo({
            url: "/hyb_yl/shopsub/pages/indent/indent"
          });
        }
      },
      fail: function(t) {
        wx.showToast({
          title: "系统繁忙，请稍后重试",
          icon: "none",
          duration: 3e3
        });
      },
      complete: function() {}
    }), this.setData({
      shopBoo: !0
    });
  },
  getProduct: function(t, a) {
    var o = this;
    wx.request({
      url: e.globalData.httpOne + "mall/item/detail/" + a + "/" + t,
      success: function(t) {
        if (200 == t.data.code && null != t.data.data) {
          var a = t.data.data.estimates;
          null != a && a.forEach(function(t) {
            t.createTime = o.toDate(t.createTime), t.star = e.starFun(t.star);
          }), o.setData({
            proList: t.data.data,
            estimates: a
          });
        }
        12020203 == t.data.code && wx.showModal({
          title: "商品已下架",
          showCancel: !1,
          confirmColor: "#3b4ca9",
          confirmText: "返回",
          success: function(t) {
            t.confirm ? wx.navigateBack({
              delta: 1
            }) : t.cancel;
          }
        });
      },
      fail: function(t) {
        wx.showToast({
          title: "网页开小差，请下拉刷新试试~~",
          icon: "none",
          duration: 3e3
        });
      },
      complete: function() {
        wx.hideLoading();
      }
    });
  },
  look_promotion: function() {
    var t = this.data.promotionBoo;
    this.setData({
      promotionBoo: !t
    });
  },
  toDate: function(t) {
    var a = t,
      e = new Date(a);
    return e.getFullYear() + "." + ((e.getMonth() + 1 < 10 ? "0" + (e.getMonth() + 1) : e.getMonth() + 1) + ".") + (e.getDate() < 10 ? "0" + e.getDate() : e.getDate());
  },
  getGoodshoping: function (sid){
    var that = this
    app.util.request({
      'url': 'entry/wxapp/Goodshoping',
      data: {
        sid: sid
      },
      success: function (res) {
        console.log(res)
        that.setData({
          proList: res.data,
        })
      }
    })
  }
});